package com.umakr.ax.app.web;


import com.google.common.collect.ImmutableMap;
import com.umakr.ax.app.service.MsgAppService;
import com.umakr.ax.app.vo.MsgParamsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.umakr.ax.core.base.AbstractController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 消息  前端控制器
 * </p>
 *
 * @author Umakr-Code-Generator
 * @since 2017-12-30
 */
@Controller
@RequestMapping("/api/msg")
public class MsgController extends AbstractController {

	@Autowired
	MsgAppService msgAppService;

	private  static final String  RADIO_ID= "电台ID=";
	private  static final String USER_ID = ";用户ID=";
	private  static final String RADIO_CODE = ";电台编码=";

	@RequestMapping(value = "/sendMsgToRs",method = RequestMethod.POST)
	@ResponseBody
	public Object upload(ModelMap modelMap,
						MsgParamsVO paramsVO,
						 @RequestParam(value = "file",required = false) MultipartFile file){
		logger.info("------------------发送语音消息开始："+RADIO_ID+paramsVO.getRsId()+USER_ID+paramsVO.getUserId()+RADIO_CODE+paramsVO.getRsCode());
		Object object = msgAppService.sendMsgToRs(paramsVO,file);
		if(object == null){
			logger.info("------------------发送语音消息未知错误："+RADIO_ID+paramsVO.getRsId()+USER_ID+paramsVO.getUserId()+RADIO_CODE+paramsVO.getRsCode());
			return setSuccessModelMap(modelMap, ImmutableMap.of("errorCode",0,"msg","未知错误。"));
		}
		logger.info("------------------发送语音消息成功："+RADIO_ID+paramsVO.getRsId()+USER_ID+paramsVO.getUserId()+RADIO_CODE+paramsVO.getRsCode());
		return setSuccessModelMap(modelMap, object);
	}
}